﻿#ifndef MYGRAPHICSSCENE_H
#define MYGRAPHICSSCENE_H



#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsEllipseItem>
#include <QDebug>
#include "MyPic.h"
#include "DraggablePoint.h"

class MyGraphicsScene : public QGraphicsScene {
public:
    MyGraphicsScene(QObject* parent = nullptr) : QGraphicsScene(parent) {

              QPixmap pixmap("i:/a.jpg");
              MyPic *myPic = new MyPic(pixmap);
              // 获取图片的宽度和高度
              qreal picWidth = pixmap.width();
              qreal picHeight = pixmap.height();

              // 左上角
              DraggablePoint* topLeft = new DraggablePoint(0, 0, 10, 10);
              addItem(topLeft);

              // 右上角
              DraggablePoint* topRight = new DraggablePoint(picWidth, 0, 10, 10);
              addItem(topRight);

              // 左下角
              DraggablePoint* bottomLeft = new DraggablePoint(0, picHeight, 10, 10);
              addItem(bottomLeft);

              // 右下角
              DraggablePoint* bottomRight = new DraggablePoint(picWidth, picHeight, 10, 10);
              addItem(bottomRight);

              // 设置图片的大小和位置



              myPic->addCornerPoint(topLeft);
              myPic->addCornerPoint(topRight);
              myPic->addCornerPoint(bottomLeft);
              myPic->addCornerPoint(bottomRight);


              // 设置图片位置
              QPointF picPos(0, 0); // 左上角为原点
              myPic->setPos(picPos);

              // 设置图片大小
              QSize picSize(picWidth, picHeight);
              myPic->setPixmap(pixmap.scaled(picSize));

              myPic->setZValue(-1); // 设置 Z 值为较低的值
              addItem(myPic);
    }
};

#endif
